<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    (function(){
        function Observer(){
            this.obj={}
            //订阅消息
            this.on=function(type,handler){
                this.obj[type]=this.obj[type] || []
                this.obj[type].push(handler)
            }
            //发布消息
            this.emit=function(type,msg){
                if(this.obj[type]){
                    this.obj[type].forEach((item)=>{
                        item(msg)
                    })
                }
            }
        }
        window.Observer=Observer
    })()
    //实例化对象
    var os=new Observer()
    //订阅消息
    os.on('李佳奇',function(msg){
        console.log('丽丽收到了李佳奇的消息'+msg);

    })
    os.emit('李佳奇','周六补课')
    // console.log(os);
</script>
</html>